package commands;

import nanoxml.XMLElement;
import utils.ITransmittable;

/**
 * This command represents a situation when a client leaves 
 * an existing table. 
 */
public class CommandLeaveTable implements ITransmittable {

	private final static String ATTR_USER_NAME = "Username";
	private final static String ATTR_TABLE_NUM = "TableNum";	
	
	private String username = null; 
	private int tableNum; 
	
	public CommandLeaveTable (String username,int tableNum) {
		this.username = username;
		this.tableNum = tableNum;
	}
	
	public CommandLeaveTable (XMLElement command) {
		this((String)command.getAttribute(ATTR_USER_NAME), command.getIntAttribute(ATTR_TABLE_NUM));
	}
	
	
	@Override
	public XMLElement toXML() {
		XMLElement message  = new XMLElement();
		message.setName(Commands.LEAVE_TABLE);
		message.setAttribute(ATTR_USER_NAME, username);
		message.setIntAttribute(ATTR_TABLE_NUM,tableNum );
		return message;
	}
	
	public String getUsername()
	{
		return username;
	}
	
	public int getTableNum()
	{
		return tableNum;
	}
}
